<?php
namespace Core\CoreContracts;

/**
* Document class definition 
*/
class Document {

	/**
    * @property integer $Id The document unique identifier
    */
	public $Id;
	
	/**
    * @property string $Name The document name
    */
	public $Name;
	
	/**
    * @property string $Path The document path
    */
	public $Path;
	
	/**
    * @property boolean $IsFolder The document is a folder
    */
	public $IsFolder;
	
	/**
    * @property boolean $IsFolderLink The document is a folder link
    */
	public $IsFolderLink;
	
	/**
    * @property integer $ParentId The parent id document
    */
	public $ParentId;
	
	/**
	* The default constructor
	*/
	public function __construct()  {  }
	
	/*
	* Build a new document object
	*
	* @param integer $id The document id
	* @param string $name The document name
	* @param string $path The document path
	* @param boolean $isFolder The document is a folder
	* @param integer $parentId The parent id document
	*/
	public static function Create($id, $name, $path, $isFolder, $parentId = -1)
	{
		$document = new Document();
		$document->Id = $id;
		$document->Path = $path;
		$document->Name =  htmlentities($name);
		$document->IsFolder = $isFolder;
		$document->IsFolderLink = $isFolder;
		$document->ParentId = $parentId;
		
		return $document ;
	}
	
	/*
	* Compare two documents
	*
	* @param Document $a The document a
	* @param Document $b The document b
	*/
	static function Compare($a, $b)
    {
        if ($a->ParentId == $b->ParentId) 
		{
			return 0;
		}
		return ($a->ParentId < $b->ParentId) ? -1 : 1;
    }
}
?> 